package a.codetop.归并;

public class 工具_合并有序数组 {

    //--合并有序数组
    private int[] 合并有序数组(int[] nums1, int[] nums2) {
        int n1=nums1.length, n2=nums2.length;
        int[] res = new int[n1+n2];//新空间
        int h1=0,h2=0,i=0;
        while(h1<n1&&h2<n2){
            if(nums1[h1]<=nums2[h2])res[i++]=nums1[h1++];
            else res[i++]=nums2[h2++];
        }

        if(h1==n1){
            for(int k=h2;k<n2;k++)res[i++]=nums2[k];
        }else if(h2==n2){
            for(int k=h1;k<n1;k++)res[i++]=nums1[k];
        }
        return res;
    }

}
